﻿using System;

namespace ReadyApps.Common
{
    /// <summary>
    /// Represents the mapping from a given URL prefix to its associated handler.
    /// </summary>
    public sealed class WikiMapping
    {
        #region Properties

        /// <summary>
        /// Gets the name of the configured route.
        /// </summary>
        public string Name { get; private set; }

        /// <summary>
        /// Gets the prefix to use when creating the route.
        /// </summary>
        public string UrlPrefix { get; private set; }

        /// <summary>
        /// Gets the handler that URLs that match this route should be directed
        /// to.
        /// </summary>
        public string MapTo { get; private set; }

        #endregion

        #region Constructor

        /// <summary>
        /// Creates a new <see cref="WikiMapping"/> object with the supplied route name,
        /// URL prefix, and mapped handler.
        /// </summary>
        /// <remarks>
        /// The mapped handler should have an application-based URL beginning with the tilde
        /// (~) character such as <c>~/Handler.aspx</c>.
        /// </remarks>
        /// <param name="name">The route name</param>
        /// <param name="urlPrefix">The prefix to append to the route pattern</param>
        /// <param name="mapTo">The application-based request handler</param>
        public WikiMapping(string name, string urlPrefix, string mapTo)
        {
            Name = name;
            UrlPrefix = urlPrefix;
            MapTo = mapTo;
        }

        #endregion

        #region Public Methods

        /// <summary>
        /// Gets the formatted route URL for the <see cref="WikiMapping"/>.
        /// </summary>
        /// <returns>The formatted route URL</returns>
        public string GetRouteUrl()
        {
            return string.Format("{0}/{{*{1}}}", UrlPrefix, Application.PATH_DATA_KEY);
        }

        #endregion
    }
}
